# _*_ encoding:utf-8 _*_
from datetime import datetime

from django.db import models


# Create your models here.
class Course(models.Model):
    name = models.CharField(max_length = 50, verbose_name = u'课程名称')
    desc = models.CharField(max_length = 100, verbose_name = u'课程描述')
    detial = models.TextField(verbose_name = u'课程详情')
    learn_times = models.IntegerField(default = 0, verbose_name = u'学习时长') #单位为分钟
    level = models.CharField(max_length = 15, choices = [('primary',u'初级'),('intermediate',u'中级'),('high',u'高级')], verbose_name = '等级', default = 'primary')
    students = models.IntegerField(default = 0, verbose_name = u'学生人数')
    favorites_num = models.IntegerField(default = 0, verbose_name = u'收藏人数')
    click_num = models.IntegerField(default = 0, verbose_name = u'点击数')
    image = models.ImageField(upload_to = 'course/%Y/%m', verbose_name = u'图片', max_length = 100)
    add_time = models.DateTimeField(default = datetime.now, verbose_name = u'添加时间')

    class Meta:
        verbose_name = u'课程'
        verbose_name_plural = verbose_name


class Lesson(models.Model):
    course = models.ForeignKey(to = Course, verbose_name = u'课程', on_delete=models.SET_NULL, null = True)
    name = models.CharField(max_length = 50, verbose_name = u'章节名称')
    add_time = models.DateTimeField(default = datetime.now, verbose_name = u'添加时间')

    class Meta:
        verbose_name = u'章节'
        verbose_name_plural = verbose_name


class Video(models.Model):
    lesson = models.ForeignKey(to = Lesson, verbose_name = u'章节', on_delete=models.SET_NULL, null = True)
    name = models.CharField(max_length = 50, verbose_name = u'视频名')
    add_time = models.DateTimeField(default = datetime.now, verbose_name = u'添加时间')

    class Meta:
        verbose_name = u'视频'
        verbose_name_plural = verbose_name


class Source(models.Model):
    course = models.ForeignKey(to = Course, verbose_name = u'课程', on_delete=models.SET_NULL, null = True)
    name = models.CharField(max_length = 50, verbose_name = u'资源名称')
    file = models.FileField(upload_to = 'sources/%Y/%m', verbose_name=u'资源文件', max_length = 100)

    class Meta:
        verbose_name = u'资源'
        verbose_name_plural = verbose_name
